<template>
	<view>
		<view class="formlist inputtext">
			<view class="formgroup border-bottom-E3E3E5">
				<view class="labletitle" v-if="showLabel" style="line-height: 65rpx;">
					<label>{{label}}</label>
					<text class="required" v-show="required">*</text>
				</view>
				<view class="controlvalue">
					<switch :checked="valueTitle" @change="switchChange($event,vModel)" style="transform:scale(0.7)" v-model="valueTitle" :disabled='disabled'/>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props:{
			value:0,
			vModel:{
				type:String,
				default(){
					return ''
				}
			},
			disabled:{
				type:Boolean,
				default(){
					return false
				}
			},
			showLabel:{
				type:Boolean,
				default(){
					return true
				}
			},
			required:{
				type:Boolean,
				default(){
					return false
				}
			},
			label:{
				type:String,
				default(){
					return '控件标题'
				}
			},
			
		},
		data() {
			return {
				valueTitle:''
			};
		},
		
		created() {
			this.valueTitle = false
			if(this.value == 1){
				this.valueTitle = true
			}
			
		},
		watch:{
			value(val){
				this.valueTitle = val
			}
		},
		methods:{
			/* 开关 */
			switchChange(e, vModel) {
				
				this.valueTitle = e.detail.value
				this.$emit('input',this.valueTitle)
			},
		}
	}
</script>

<style>
	.required{
		color: red;
	}
</style>
